//
//  SecondViewController.m
//  UI07_homework
//
//  Created by aaaaaa on 16/6/14.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "SecondViewController.h"
#import "ViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"Second";
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self createScrollView];
    
}

- (void)createScrollView{
    ViewController *vc = [self.navigationController.viewControllers objectAtIndex:0];
    self.imageViewArray = vc.imageViewArray;
    self.tag = vc.tag;
    
    
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 192 * 2 ,108 * 2)];
    scrollView.center = self.view.center;
    scrollView.contentSize = CGSizeMake(scrollView.bounds.size.width * self.imageViewArray.count, 0);
    
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.pagingEnabled = YES;
//    scrollView.bounces = NO;

    for (int i = 0; i < self.imageViewArray.count; i++) {
//        self.imageViewArray[i].frame = CGRectMake(CGRectGetWidth(scrollView.bounds) * i, 0, CGRectGetWidth(scrollView.bounds), CGRectGetHeight(scrollView.bounds));
//        [scrollView addSubview:self.imageViewArray[i]];
        
        UIImage *image = self.imageViewArray[i].image;
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        imageView.frame = CGRectMake(CGRectGetWidth(scrollView.bounds) * i , 0 - 60, CGRectGetWidth(scrollView.bounds), CGRectGetHeight(scrollView.bounds));;
        [scrollView addSubview:imageView];
        [imageView release];
        if (self.imageViewArray[i].tag == self.tag) {
            scrollView.contentOffset = CGPointMake(CGRectGetWidth(scrollView.bounds) * i, 0);
        }
    }
    [self.view addSubview:scrollView];
    [scrollView release];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
